(function() {
    let newData = [];
    let pageid = 1;
    let left = document.querySelector(".left")
    let rigth = document.querySelector(".rigth")
    let info = document.querySelector(".info")
    function render(data = []) {
        newData = [...newData ,  ...data]
        let html = "";
        newData.forEach(item => {
            html += `
            <li>
            <a href="detail.html?productid=${item.productId}" class="clearfix">
                <div class="img">
                    ${item.productImgSm}
                </div>
                <div class="infoR">
                    <div class="title">
                        <h4>
                        ${item.productName} 
                        </h4>
                    </div>
                    <div class="other">
                        <span>${item.productFrom} | ${item.productTime}</span>
                        <i>${item.productComCount}</i>
                    </div>
                </div>
            </a>
        </li>
            `
        })
        info.innerHTML = html;
        
    }
    function testButton() {
                
        left.disabled = true; //使用true或false，控制是否让按钮禁用
    }
    rigth.addEventListener('click',function() { 
        pageid ++;
        if(pageid === 14) {
			rigth.disabled = true;
		}else {
            rigth.disabled = false;
            left.disabled = false;
        }
        console.log(pageid);
        newData = [];
        ajax({
            url: "http://chst.vip:1234/api/getmoneyctrl",
                data: {
                    pageid
                }
            })
                .then(res => {
                    console.log(res);
                    render(res.result)
                } , error => {
                    console.error("出错了");
        })
    })    
    left.addEventListener('click',function() { 
        pageid --;
        if(pageid === 1) {
			left.disabled = true;
		}else {
            rigth.disabled = false;
            left.disabled = false;
        }
        console.log(newData);
        newData = [];
        ajax({
            url: "http://chst.vip:1234/api/getmoneyctrl",
                data: {
                    pageid
                }
            })
                .then(res => {
                    console.log(res);
                    render(res.result)
                } , error => {
                    console.error("出错了");
        })
    })    
    ajax({
        url: "http://chst.vip:1234/api/getmoneyctrl",
            data: {
                pageid
            }
        })
            .then(res => {
                console.log(res);
                render(res.result)
            } , error => {
                console.error("出错了");
    })

})()